package org.jeecg.modules.wflow.utils;


//import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.shiro.JwtToken;
import org.jeecg.modules.wflow.bean.vo.UserLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

/**
 * @author : willian fu
 * @date : 2022/9/29
 */
public class UserUtil {

    /**
     * 获取当前登录用户的id
     * @return 用户ID
     */
    public static String getLoginUserId(){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        System.out.println("++++++++++++getLoginUserId start+++++++++++++++++");
        System.out.println(JSON.toJSON(loginUser));
        System.out.println("++++++++++++getLoginUserId end++++++++++++++++++");
        return loginUser.getId();
    }

    /**
     * 获取当前用户租户ID
     * @return 租户ID
     */
    public static String getLoginTenantId(){
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        return Optional.ofNullable(request.getHeader("tenant-id")).orElse("1");
    }
}
